package com.atguigu.hadoop.examples.mapreduce.wordMedian;


import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;
import java.util.StringTokenizer;

public  class WordMedianMapper extends Mapper<Object, Text, IntWritable, IntWritable>
{
    private IntWritable length = new IntWritable();

    public void map(Object key, Text value, Mapper<Object, Text, IntWritable, IntWritable>.Context context)
            throws IOException, InterruptedException
    {
        StringTokenizer itr = new StringTokenizer(value.toString());
        while (itr.hasMoreTokens()) {
            String string = itr.nextToken();
            this.length.set(string.length());
            context.write(this.length, WordMedian.ONE);
        }
    }
}